Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move blocking readPair call to boundedElastic thread #1653

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Arooba-git
Copy link
Contributor

@Arooba-git Arooba-git commented Jul 23, 2023

Hi! 🙂

We noticed you did a great job in ensuring the reactive modules indeed stay reactive end to end. The mailbox module, however, was discovered to still have a blocking call in CassandraMessageMapper class as detected by BlockHound:
james3-blocking

This PR fixes this code. We also re-ran the tests and verified the performance (in terms of heap usage) before and after the fix:

Before
james3-heap-before

After

james3-heap-after

Copy link
Contributor

@quantranhong1999 quantranhong1999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution <3

.doOnNext(counters -> readRepair(mailbox, counters));
.doOnNext(counters -> {
Mono.fromRunnable(() -> {
readRepair(mailbox, counters);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we manage to subscribe here only if read repairs are enabled ie probability > 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, you mean something like:

.doOnNext(counters -> {
       if (probability > 0) {
              Mono.fromRunnable(() -> {
                   readRepair(mailbox, counters);
              })
             .subscribeOn(Schedulers.boundedElastic())
             .subscribe();
       }
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chibenwa I'm sorry could you guide how to access probability property here? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the configuration

@Arooba-git Arooba-git force-pushed the fix-blocking-call-in-mailbox branch from d2c426a to dec0b5d Compare July 24, 2023 06:41
@@ -170,7 +170,16 @@ public Mono<MailboxCounters> getMailboxCountersReactive(Mailbox mailbox) {
}
return Mono.just(counters);
})
.doOnNext(counters -> readRepair(mailbox, counters));
.doOnNext(counters -> {
if (this.cassandraConfiguration.getMailboxReadRepair() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm oretty sure it should be

Suggested change
if (this.cassandraConfiguration.getMailboxReadRepair() > 0) {
if (this.cassandraConfiguration.getMailboxCountersReadRepair() > 0) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you mean we should update the name in the original configuration file too? 🤔
Screen Shot 2023-07-25 at 12 13 15 AM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe what chibenwa is saying is:

  • getMailboxReadRepair() is used in CassandraMailboxMapper
  • for CassandraMessageMapper , we use getMailboxCountersReadRepairChanceMax() and/or getMailboxCountersReadRepairChanceOneHundred()

=> for example: https://github.com/apache/james-project/blob/master/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java#L197

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could extract that line actually in a function to avoid duplication, that we could call from there and from your code change :)

@chibenwa
Copy link
Contributor

Also read repair could be a good place for pseudo random usage aka non blocking...

There is no need for cryptographioc grade randomness for such an application.

Maybe otherall this could be a better fix. WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants